<?php
function smarty_modifier_video_replace($string)
{
	// replace codes for youtube and rutube 
	
	$expr = "/<(rutube|youtube) videoid=\"([_a-zA-Z0-9\-]+)\">/";
	while (preg_match($expr, $string, $out)) {
		$tag = $out[0];
		$service = $out[1];
		$id = $out[2];
		
		$result = '';
		if($service=='rutube') $result = '<div style="margin:10px 0;"><OBJECT width="470" height="353"><PARAM name="movie" value="http://video.rutube.ru/'.$id.'"></PARAM><PARAM name="wmode" value="transparent"></PARAM><PARAM name="allowFullScreen" value="true"></PARAM><EMBED src="http://video.rutube.ru/'.$id.'" type="application/x-shockwave-flash" wmode="transparent" width="470" height="353" allowFullScreen="true" ></EMBED></OBJECT></div>';
		if($service=='youtube') $result = '<div style="margin:10px 0;"><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/'.$id.'&hl=ru&fs=1"></param><PARAM name="wmode" value="transparent"><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$id.'&hl=ru&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295" wmode="transparent"></embed></object></div>';
		
		$string = str_replace($tag, $result, $string);
	}
	
	return lightboxable($string);
}




function lightboxable($string)
{
	$expr = "|<img[^>]*src=\"/data/cache/(\d{4}\w{3})\/(\d{2})\/(\d{2})/([0-9_]+)thumb([0-9]*).jpg\"[^>]*>|i";
	$replace = "<a href=\"/data/cache/\$1/\$2/\$3/\$4-700x700.jpg\" rel=\"facebox\" class=\"justbox\">\$0</a><br>";
	$string = preg_replace($expr,$replace,$string);
	
	return $string;	
}
